class StringTable
{
	char ** array;
	int     *count;
	int     size;
	int     numStrings;

public:
	StringTable() {
		size = 20;
		array = new char *[size];
		count = new int[size];
		numStrings = 0;
	}

	int addString(const char *ch) {
		int i = 0; 
		for (; i < numberStrings; i++) {
			if (strcmp(ch, array[i]) == 0) {
				count[i]++;
				return i;
			}
		}
		if (i == size) {
			return -1;
		} 
		
		array[i] = new char[strlen(ch)+1];
		strcpy(array[i], ch);
		return numStrings++;
	}

	char * getString(int index) const {
		return array[index];
	}
};

char String
{
	int length;
	char *text;
	int index;

public:
	static StringTable *table;

	String(const char *ch) {
		length = strlen(ch);
		text = new char[length+1];
		strcpy(text, ch);
		index = table->addString(text);
	}

	char* intern() {
		if (index == -1)
			return 0;
		else 
			return table->getString(index);
	}
};

StringTable* String::table = new StringTable();
